package com.xuzz.xrpc.spring.context;

import com.xuzz.xrpc.common.ConfigManager;
import com.xuzz.xrpc.common.PropertyConfig;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Scanner;

/**
 * @description:
 * @author: xuzz
 * @create: 2020-02-21 17:26
 */
public class BootstrapApplicationListener extends OneTimeExecutionApplicationContextEventListener {


    @Override
    public void onApplicationContextEvent(ApplicationContextEvent event) {
        if (event instanceof ContextRefreshedEvent) {
            onContextRefreshedEvent((ContextRefreshedEvent) event);
        } else if (event instanceof ContextClosedEvent) {
            onContextClosedEvent((ContextClosedEvent) event);
        }
    }

    public void onContextRefreshedEvent(ApplicationEvent event) {

        XPRCServerBootstrap.getInstance()
                .setApplicationContext(applicationContext)
                .start();
    }

    private void onContextClosedEvent(ContextClosedEvent event) {

        System.out.println("退出");
    }
}
